/*
 * key_task.c
 *
 *  Created on: 2024年8月15日
 *      Author: nwz
 */
#include <all_header.h>

#define DELAY_TIME	100
void key_task_run(void *arg) {
	uint8_t cnt = 0;
	while (HAL_GPIO_ReadPin(KEY_ON_OFF_GPIO_Port, KEY_ON_OFF_Pin)
			== GPIO_PIN_RESET) { // wait until release key
		DELAY(DELAY_TIME);
	}

	while (true) {
		if (HAL_GPIO_ReadPin(KEY_ON_OFF_GPIO_Port, KEY_ON_OFF_Pin)
				== GPIO_PIN_RESET) {
			cnt++;
			if (cnt > BTN_LONG_CLICK_TIME / DELAY_TIME) {
				cnt = 0;
				RESET();
			}
		} else {
			cnt = 0;
		}
		DELAY(DELAY_TIME);
	}
}

bool key_task_k1_is_down(void) {
	return HAL_GPIO_ReadPin(KEY_K1_GPIO_Port, KEY_K1_Pin) == GPIO_PIN_RESET;
}
